package com.nondo.rdp.finance.repository.course;

import java.util.List;
import java.util.Optional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.nondo.rdp.core.common.StatusConstant;
import com.nondo.rdp.finance.domain.course.Section;

public interface SectionRepository extends JpaRepository<Section, Long>,
        JpaSpecificationExecutor<Section> {
    @Query("select a from Section a where a.id=:id and delFlag = '" + StatusConstant.DEL_FLAG_NORMAL + "'")
    Optional<Section> findOne(@Param("id") int id);

    @Modifying
    @Query("update Section set delFlag='" + StatusConstant.DEL_FLAG_DELETE + "' where id = ?1")
    void deleteById(Long id);

    Section save(Section Section);

    @Query("select a.course.id from Section a where a.id=?")
    Long getCourseId(Long sectionId);

    Section findByAlbumIdAndTrackId(int albumId, int trackId);

    @Query("select a from Section a where a.course.id=:cid and delFlag = '" + StatusConstant.DEL_FLAG_NORMAL + "'")
	List<Section> findByCourseId(@Param("cid") Long cid);
}
